home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d18
/
nrpas13.arc
/
RAN3.DEM
< prev
next >
Wrap
Text File
|
1991-05-01
|
2KB
|
58 lines
PROGRAM d7r4 (input,output);
(* driver for routine RAN3 *)
(* calculates pi statistically using volume of unit n-sphere *)
CONST
pi=3.1415926;
VAR
i,idum,j,k,jpower : integer;
x1,x2,x3,x4 : real;
iy : ARRAY [1..3] OF integer;
yprob : ARRAY [1..3] OF real;
glinext,glinextp : integer;
glma : ARRAY [1..55] OF real;
FUNCTION fnc(x1,x2,x3,x4 : real) : real;
BEGIN
fnc := sqrt(sqr(x1)+sqr(x2)+sqr(x3)+sqr(x4))
END;
FUNCTION twotoj(j : integer) : integer;
BEGIN
IF (j=0) THEN twotoj := 1
ELSE twotoj := 2*twotoj(j-1)
END;
(*$I MODFILE.PAS *)
(*$I RAN3.PAS *)
BEGIN
idum := -1;
FOR i := 1 to 3 DO BEGIN
iy[i] := 0
END;
writeln;
writeln ('volume of unit n-sphere, n := 2,3,4');
writeln ('# points',' pi ',' (4/3)*pi ',' (1/2)*pi^2 ');
writeln;
FOR j := 1 to 13 DO BEGIN
FOR k := twotoj(j-1) to twotoj(j) DO BEGIN
x1 := ran3(idum);
x2 := ran3(idum);
x3 := ran3(idum);
x4 := ran3(idum);
IF (fnc(x1,x2,0.0,0.0) < 1.0) THEN iy[1] := iy[1]+1;
IF (fnc(x1,x2,x3,0.0) < 1.0) THEN iy[2] := iy[2]+1;
IF (fnc(x1,x2,x3,x4) < 1.0) THEN iy[3] := iy[3]+1
END;
FOR i := 1 to 3 DO BEGIN
jpower := twotoj(j);
yprob[1] := 4.0*iy[1]/jpower;
yprob[2] := 8.0*iy[2]/jpower;
yprob[3] := 16.0*iy[3]/jpower
END;
writeln (jpower:6,yprob[1]:12:6,yprob[2]:12:6,yprob[3]:12:6)
END;
writeln;
writeln ('actual',pi:12:6,(4.0*pi/3.0):12:6,(0.5*sqr(pi)):12:6)
END.